home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Log / composite.php next >
PHP Script  |  2004-10-01  |  5KB  |  197 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log/composite.php,v 1.23 2004/08/09 06:04:11 jon Exp $
  4.  * $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $
  5.  *
  6.  * @version $Revision: 1.23 $
  7.  * @package Log
  8.  */
  9.  
  10. /**
  11.  * The Log_composite:: class implements a Composite pattern which
  12.  * allows multiple Log implementations to receive the same events.
  13.  *
  14.  * @author  Chuck Hagenbuch <chuck@horde.org>
  15.  * @author  Jon Parise <jon@php.net>
  16.  *
  17.  * @since Horde 1.3
  18.  * @since Log 1.0
  19.  * @package Log
  20.  *
  21.  * @example composite.php   Using the composite handler.
  22.  */
  23. class Log_composite extends Log
  24. {
  25.     /**
  26.      * Array holding all of the Log instances to which log events should be
  27.      * sent.
  28.      *
  29.      * @var array
  30.      * @access private
  31.      */
  32.     var $_children = array();
  33.  
  34.  
  35.     /**
  36.      * Constructs a new composite Log object.
  37.      *
  38.      * @param boolean   $name       This parameter is ignored.
  39.      * @param boolean   $ident      This parameter is ignored.
  40.      * @param boolean   $conf       This parameter is ignored.
  41.      * @param boolean   $level      This parameter is ignored.
  42.      *
  43.      * @access public
  44.      */
  45.     function Log_composite($name = false, $ident = false, $conf = false,
  46.                            $level = PEAR_LOG_DEBUG)
  47.     {
  48.     }
  49.  
  50.     /**
  51.      * Opens the child connections.
  52.      *
  53.      * @access public
  54.      */
  55.     function open()
  56.     {
  57.         if (!$this->_opened) {
  58.             foreach ($this->_children as $id => $child) {
  59.                 $this->_children[$id]->open();
  60.             }
  61.             $this->_opened = true;
  62.         }
  63.     }
  64.  
  65.     /**
  66.      * Closes any child instances.
  67.      *
  68.      * @access public
  69.      */
  70.     function close()
  71.     {
  72.         if ($this->_opened) {
  73.             foreach ($this->_children as $id => $child) {
  74.                 $this->_children[$id]->close();
  75.             }
  76.             $this->_opened = false;
  77.         }
  78.     }
  79.  
  80.     /**
  81.      * Flushes all open child instances.
  82.      *
  83.      * @access public
  84.      * @since Log 1.8.2
  85.      */
  86.     function flush()
  87.     {
  88.         if ($this->_opened) {
  89.             foreach ($this->_children as $id => $child) {
  90.                 $this->_children[$id]->flush();
  91.             }
  92.         }
  93.     }
  94.  
  95.     /**
  96.      * Sends $message and $priority to each child of this composite.
  97.      *
  98.      * @param mixed     $message    String or object containing the message
  99.      *                              to log.
  100.      * @param string    $priority   (optional) The priority of the message.
  101.      *                              Valid values are: PEAR_LOG_EMERG,
  102.      *                              PEAR_LOG_ALERT, PEAR_LOG_CRIT,
  103.      *                              PEAR_LOG_ERR, PEAR_LOG_WARNING,
  104.      *                              PEAR_LOG_NOTICE, PEAR_LOG_INFO, and
  105.      *                              PEAR_LOG_DEBUG.
  106.      *
  107.      * @return boolean  True if the entry is successfully logged.
  108.      *
  109.      * @access public
  110.      */
  111.     function log($message, $priority = null)
  112.     {
  113.         /* If a priority hasn't been specified, use the default value. */
  114.         if ($priority === null) {
  115.             $priority = $this->_priority;
  116.         }
  117.  
  118.         foreach ($this->_children as $id => $child) {
  119.             $this->_children[$id]->log($message, $priority);
  120.         }
  121.  
  122.         $this->_announce(array('priority' => $priority, 'message' => $message));
  123.  
  124.         return true;
  125.     }
  126.  
  127.     /**
  128.      * Returns true if this is a composite.
  129.      *
  130.      * @return boolean  True if this is a composite class.
  131.      *
  132.      * @access public
  133.      */
  134.     function isComposite()
  135.     {
  136.         return true;
  137.     }
  138.  
  139.     /**
  140.      * Sets this identification string for all of this composite's children.
  141.      *
  142.      * @param string    $ident      The new identification string.
  143.      *
  144.      * @access public
  145.      * @since  Log 1.6.7
  146.      */
  147.     function setIdent($ident)
  148.     {
  149.         foreach ($this->_children as $id => $child) {
  150.             $this->_children[$id]->setIdent($ident);
  151.         }
  152.     }
  153.  
  154.     /**
  155.      * Adds a Log instance to the list of children.
  156.      *
  157.      * @param object    $child      The Log instance to add.
  158.      *
  159.      * @return boolean  True if the Log instance was successfully added.
  160.      *
  161.      * @access public
  162.      */
  163.     function addChild(&$child)
  164.     {
  165.         /* Make sure this is a Log instance. */
  166.         if (!is_a($child, 'Log')) {
  167.             return false;
  168.         }
  169.  
  170.         $this->_children[$child->_id] = &$child;
  171.  
  172.         return true;
  173.     }
  174.  
  175.     /**
  176.      * Removes a Log instance from the list of children.
  177.      *
  178.      * @param object    $child      The Log instance to remove.
  179.      *
  180.      * @return boolean  True if the Log instance was successfully removed.
  181.      *
  182.      * @access public
  183.      */
  184.     function removeChild($child)
  185.     {
  186.         if (!is_a($child, 'Log') || !isset($this->_children[$child->_id])) {
  187.             return false;
  188.         }
  189.  
  190.         unset($this->_children[$child->_id]);
  191.  
  192.         return true;
  193.     }
  194. }
  195.  
  196. ?>
  197.